package modelo;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import entities.PerfilEntity;
import entities.SucursalEntity;
import hbt.AbstractHibernateManager;


public class PerfilDao extends AbstractHibernateManager {
	
	private static PerfilDao instancia = null;
	
	public static PerfilDao getInstancia()
	{
		if(instancia == null)
		{
			instancia = new PerfilDao();
		}
		return instancia;
	}

	
	public void save (PerfilEntity perfil){
		Session s = null;
		try {
			s=getNewSession();
			s.beginTransaction();
			s.persist(perfil);
			s.flush();
			s.getTransaction().commit();
			System.out.println("[perfil SAVED ON TABLE perfiles]::OK");
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally{
			closeSession(s);
		}
	}
	
	
	public PerfilEntity obtenerPerfil(Integer id) {
		Session s = null;
		PerfilEntity perfil = new PerfilEntity();
		
		try {
			s = getNewSession();
			perfil =  (PerfilEntity) s.createQuery("FROM PerfilEntity perfil " +
									"WHERE perfil.id = :id")
							  .setInteger("id", id)
							  .uniqueResult();
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally{
			closeSession(s);
		}
		return perfil;
	}
	
	
}
